package com.lucenten.collect.gnss.handler.impl;

import cn.quevo.common.lang.StringUtils;
import com.lucenten.collect.gnss.entity.GnssFile;
import com.lucenten.collect.gnss.handler.AbstractGnssHandler;
import com.lucenten.collect.gnss.handler.GnssHandler;
import com.lucenten.collect.gnss.service.ObsErvationService;
import com.lucenten.collect.gnss.service.SatelliteStationService;
import com.lucenten.collect.utils.FileUtils;
import com.lucenten.mq.SendJmsInfo;
import org.springframework.scheduling.annotation.Async;

import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 第四步：.文件重命名
 */
public class BackupGnssHandler extends AbstractGnssHandler implements GnssHandler {

    public BackupGnssHandler(SatelliteStationService satelliteStationService, ObsErvationService obsErvationService) {
        super(satelliteStationService, obsErvationService);
    }

    @Async
    @Override
    protected boolean doProcess(GnssFile gnssFile) {
        if (!isDev) {
            FileUtils.move(Paths.get(gnssFile.getSourceFile()), Paths.get(super.getBackupPath(gnssFile),gnssFile.getLowerName()));
            if (!StringUtils.isEmpty(gnssFile.getBackList())) {
                for (String back : gnssFile.getBackList()) {
                    FileUtils.move(Paths.get(back), Paths.get(super.getBackupPath(gnssFile), gnssFile.getLowerName()));
//                    SendJmsInfo.sendGnssMq(6, back, 0);
                }
            }
        }
        return true;
    }
}
